<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>学生信息管理</title>
<script type="text/javascript">
	
	function delCook(){
		//获得选中数据对象
		var selectedRows=$("#dg").datagrid('getSelections');
		if(selectedRows.length==0){
			$.messager.alert("系统提示","请选择要删除的数据！");
			return;
		}
		var strIds=[];//要删除的序号组合
		for(var i=0;i<selectedRows.length;i++){
			strIds.push(selectedRows[i].cookid);
		}
		var ids=strIds.join(",");
		$.messager.confirm("系统提示","您确认要删掉这<font color=red>"+selectedRows.length+"</font>条数据吗？",function(r){
			if(r){
				//ajax提交 delIds
				$.post("delCookList",{cookids:ids},function(result){
					if(result){
						$.messager.alert("系统提示","您已成功删除<font color=red>"+selectedRows.length+"</font>条数据！");
						$("#dg").datagrid("reload");
					}else{
						$.messager.alert('系统提示',"删除失败");
					}
				},"json");
			}
		});
	}
	
	//查询符合条件的用户
	function searchCook(){
		$('#dg').datagrid('load',{
			cookid:$('#cookid').val(),
			cooksex:$('#cooksex').combobox("getValue"),
			cookname:$('#cookname').val(),
			cookphone:$('#cookphone').val()
		});
	}
	function openCookModifyDialog(){
		var selectedRows=$("#dg").datagrid('getSelections');
		if(selectedRows.length!=1){
			$.messager.alert("系统提示","请选择一条要编辑的数据！");
			return;
		}
		var row=selectedRows[0];
		$("#dlg").dialog("open").dialog("setTitle","编辑厨师资料");
		$("#mcookid").val(row.cookid);
		$("#mcookname").val(row.cookname);
		$("#mcooksex").combobox("setValue",row.cooksex);
		$("#mcookphone").val(row.cookphone);
	}	
	function saveCook(){
		$("#fm").form("submit",{
			url:"updateCook",
			onSubmit:function(){
				if($('#mcooksex').combobox("getValue")==""){
					$.messager.alert("系统提示","请选择性别");
					return false;
				}
				if($('#mcookphone').val()==""){
					$.messager.alert("系统提示","请输入联系方式");
					return false;
				}
				return $(this).form("validate");
			},
			success:function(result){
				if(result){
					$.messager.alert("系统提示","保存成功");
					$("#dlg").dialog("close");
					$("#dg").datagrid("reload");
				}else{
					$.messager.alert("系统提示","保存失败");
					return;
				}
			}
		});
	}
	
	//关闭对话框
	function closeCookDialog(){
		$("#dlg").dialog("close");
	}
</script>
<link rel="stylesheet" type="text/css"  href="../easyui-1.5/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css"  href="../easyui-1.5/themes/icon.css" />
<script type="text/javascript" src="../easyui-1.5/jquery.min.js"></script>
<script type="text/javascript" src="../easyui-1.5/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../easyui-1.5/locale/easyui-lang-zh_CN.js"></script>
</head>
<body style="margin:5px">
	<table id="dg" title="厨师信息" class="easyui-datagrid" fitColumns="true" striped="true"
	 pagination="true" rownumbers="true" url="getCookList" fit="true" toolbar="#tb">
		<thead>
			<tr>
				<th field="cb" checkbox="true"></th>
				<th field="cookid" width="100" align="center">用户名</th>
				<th field="cookname" width="100" align="center">姓名</th>
				<th field="cooksex" width="100" align="center">性别</th>
				<th field="cookphone" width="100"  align="center">手机号</th>				
			</tr>
		</thead>
	</table>
	<div id="tb">
		<div>
			<a href="javascript:openCookModifyDialog()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
			<a href="javascript:delCook()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
		</div>
		<div>
			<form id="export" method="post">
			&nbsp;用户名：&nbsp;<input type="text" name="cookid" id="cookid" size="10"/>
			&nbsp;性别：&nbsp;<select class="easyui-combobox" id="cooksex" name="stusex" editable="false" panelHeight="auto">
			    <option value="">请选择...</option>
				<option value="男">男</option>
				<option value="女">女</option>
			</select>
			&nbsp;姓名：&nbsp;<input type="text" name="cookname" id="cookname" size="10"/>
			&nbsp;联系方式：&nbsp;<input type="text" name="cookphone" id="cookphone" size="10"/>
			<a href="javascript:searchCook()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
			</form>
		</div>
	</div>
	<div id="dlg" class="easyui-dialog" style="width: 550px;height: 240px;padding: 10px 20px"
		closed="true" buttons="#dlg-buttons">
		<form id="fm" method="post">
			<table cellspacing="5px;">
				<tr>		
					<td>用户名：</td>
					<td><input type="text" name="cookid" id="mcookid" class="easyui-validatebox" required="true" readonly/></td>
					<td>姓名：</td>
					<td><input type="text" name="cookname" id="mcookname" class="easyui-validatebox" required="true"/></td>
				</tr>
				<tr>
					<td>性别：</td>
					<td><select class="easyui-combobox" id="mcooksex" name="cooksex" editable="false" panelHeight="auto" style="width: 155px">
					    <option value="">请选择...</option>
						<option value="男">男</option>
						<option value="女">女</option>
					</select>
					</td>
					<td>手机号：</td>
					<td><input type="text" name="cookphone" id="mcookphone" class="easyui-validatebox" data-options="required:true,validType:'length[11,11]'"/></td>
				</tr>
			</table>
		</form>
	</div>
	
	<div id="dlg-buttons">
		<a href="javascript:saveCook()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
		<a href="javascript:closeCookDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
	</div>
	
</body>
</html>